package cn.codingjc.aurora.framework.schedule.config;

import cn.codingjc.aurora.framework.schedule.core.CronTaskRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * @auth: coding_jc
 * @date: 2023/11/1 22:11
 * @desc:
 */

@AutoConfiguration
public class ScheduleAutoConfiguration {

    @Autowired
    TaskScheduler taskScheduler;

    @Bean
    public TaskScheduler taskScheduler(){
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setPoolSize(4);
        threadPoolTaskScheduler.setRemoveOnCancelPolicy(true);
        threadPoolTaskScheduler.setThreadNamePrefix("TaskSchedulerThreadPool-");
        return threadPoolTaskScheduler;
    }

    @Bean
    public CronTaskRegistry cronTaskRegistry(){
        return new CronTaskRegistry(taskScheduler);
    }
}
